package com.dalin.platform.loa.model;

import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import com.dalin.common.base.BaseObject;
import com.dalin.platform.loa.condition.LoaUserCondition;
import com.dalin.platform.pub.PlatContext;
/*****************************************************************************
 * @content: 组织结构类信息                                                                                                                    *
 * @author : 那建林                                                                                                                                 *
 * @crtDate: 2010-05-11                                                     *
 * @modDate: 2010-05-11                                                     *
 * @version: 1.00                                                           *
 ****************************************************************************/
@Entity
@Table(name="LOA_ORGANIZATION")
public class LoaOrganizationEntity extends BaseObject {
    private Long organId; // ORGAN_ID,16,0
    private Long projectId; // PROJECT_ID,16,0
    private String organType;
    private String belongAreaCode;
    private String organName; // ORGAN_NAME,256,0
    private Integer orderNumber; // SEQUENCE,4,0
    private Long parentId; // PARENT_ID,16,0
    private String description; // DESCRIPTION,256,0
    private Date createTime; // CREATE_DATE,7,0
    private Date modifyTime; // MODIFY_DATE,7,0
    private Integer flagDel; // VALID,2,0
    
    

	@Id
    @Column(name="ORGAN_ID")
    @GeneratedValue(strategy = GenerationType.TABLE,generator="generator_normal")
    @TableGenerator(
        name = "generator_normal",
        table = "GLB_GENERATOR_KEY",
        pkColumnName = "GEN_KEY",
        valueColumnName = "GEN_VALUE",
        pkColumnValue = "LOA_ORGANIZATION",
        allocationSize=1
    )
    public Long getOrganId() {
        return organId;
    }

    public void setOrganId(Long organId) {
        this.organId = organId;
    }

    @Column(name="PROJECT_ID")
    public Long getProjectId() {
		return projectId;
	}

	public void setProjectId(Long projectId) {
		this.projectId = projectId;
	}

	@Column(name="ORGAN_NAME")
    public String getOrganName() {
        return organName;
    }

    public void setOrganName(String organName) {
        this.organName = organName;
    }

    @Column(name="ORDER_NUMBER")
    public Integer getOrderNumber() {
		return orderNumber;
	}

	public void setOrderNumber(Integer orderNumber) {
		this.orderNumber = orderNumber;
	}
	
    @Column(name="PARENT_ID")
    public Long getParentId() {
        return parentId;
    }


	public void setParentId(Long parentId) {
        this.parentId = parentId;
    }

    @Column(name="DESCRIPTION")
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Column(name="BELONG_AREA_CODE")
    public String getBelongAreaCode() {
		return belongAreaCode;
	}

	public void setBelongAreaCode(String belongAreaCode) {
		this.belongAreaCode = belongAreaCode;
	}

	@Temporal(TemporalType.TIMESTAMP)
    @Column(name="CREATE_TIME")
    public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	
	
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="MODIFY_TIME")
    public Date getModifyTime() {
		return modifyTime;
	}

	public void setModifyTime(Date modifyTime) {
		this.modifyTime = modifyTime;
	}
	
    @Column(name="FLAG_DEL")
    public Integer getFlagDel() {
		return flagDel;
	}
	public void setFlagDel(Integer flagDel) {
		this.flagDel = flagDel;
	}
	
	@Column(name="ORGAN_TYPE")
    public String getOrganType() {
		return organType;
	}

	public void setOrganType(String organType) {
		this.organType = organType;
	}

	@Transient
    public List<LoaUserEntity> getLoaUserEntitys() throws Exception {
    	LoaUserCondition cond = new LoaUserCondition();
    	cond.setOrganId(this.getOrganId());
		return PlatContext.getDao().queryObjsToPages(cond.prepareParams()
				.getPreparedPageQuery());
	}

	@Override
    public int hashCode() {
        int njlrst = 17;
        njlrst = 31 * njlrst + (organId == null ? 0 : organId.hashCode());
        njlrst = 31 * njlrst + (projectId == null ? 0 : projectId.hashCode());
        njlrst = 31 * njlrst + (organName == null ? 0 : organName.hashCode());
        njlrst = 31 * njlrst + (parentId == null ? 0 : parentId.hashCode());
        njlrst = 31 * njlrst + (description == null ? 0 : description.hashCode());
        return njlrst;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof LoaOrganizationEntity)) return false;
        final LoaOrganizationEntity other = (LoaOrganizationEntity) o;
        if (organId == null) {
            if (other.organId != null) return false;
        } else if (!organId.equals(other.organId)) {
            return false;
        }
        if (projectId == null) {
            if (other.projectId != null) return false;
        } else if (!projectId.equals(other.projectId)) {
            return false;
        }
        if (organName == null) {
            if (other.organName != null) return false;
        } else if (!organName.equals(other.organName)) {
            return false;
        }
        if (parentId == null) {
            if (other.parentId != null) return false;
        } else if (!parentId.equals(other.parentId)) {
            return false;
        }
        if (description == null) {
            if (other.description != null) return false;
        } else if (!description.equals(other.description)) {
            return false;
        }
        return true;
    }
}
